package settings;

import fileHandling.language.options.Graphics;
import fileHandling.language.options.OptionValues;

import logic.nodes.nodeSettings.Settings;

import com.jme.image.Texture;

public class GraphicSettings extends ConfigFile {
	
	private static GraphicSettings settings = new GraphicSettings();
	
	private GraphicSettings() {
		super();
	}
	
	public static GraphicSettings copySettings() {
		GraphicSettings settings = new GraphicSettings();
		settings.copySettings(GraphicSettings.get(), true);
		return settings;
	}
	
	public static GraphicSettings get() { return settings; }
	
	@Override
	public String getFileName() { return "graphics.xml"; }
	
	@Override
	public void reset() { settings = new GraphicSettings(); }
	
	@Override
	protected Settings getSettings() { return settings; }
	
	public void setResolution(String res) { addOption(Graphics.Resolution, res); }
	public String getResolutionString() { return getValueOf(Graphics.Resolution); }
	public int[] getResolution() {
		String[] resArray = getResolutionString().split("x");
		return new int[] { Integer.valueOf(resArray[0]).intValue(), Integer.valueOf(resArray[1]).intValue() };
	}
	
	public void setFullscreen(String fullscreen) { addOption(Graphics.Fullscreen, fullscreen); }
	public String getFullscreenString() { return getValueOf(Graphics.Fullscreen); }
	public boolean getFullscreen() { return Boolean.valueOf(getFullscreenString()).booleanValue(); }
	
	public void setDetails(String details) { addOption(Graphics.Details, details); }
	public String getDetailsString() { return getValueOf(Graphics.Details); }
	public String getDetails() { return getOptionValueString(getDetailsString()); }
	
	public void setFPS(String fps) { addOption(Graphics.FPS, fps); }
	public String getFPSString() { return getValueOf(Graphics.FPS); }
	public int getFPS() { return Integer.valueOf(getFPSString()).intValue(); }
	
	public void setShadow(String shadow) { addOption(Graphics.Shadows, shadow); }
	public String getShadowString() { return getValueOf(Graphics.Shadows); }
	public boolean getShadowEnabled() { return getShadowString().equals("true"); }
	
	public void setTextureFilter(String textureFilter) { addOption(Graphics.Texture_Filter, textureFilter); }
	public String getTextureFilterString() { return getValueOf(Graphics.Texture_Filter); }
	public Texture.MinificationFilter getMinificationFilter() {
		if(getTextureFilterString().equals(OptionValues.Trilinear.toString())) 
			return Texture.MinificationFilter.Trilinear;
		return Texture.MinificationFilter.BilinearNearestMipMap;
	}
	
	public void setAnisotrop(String anisotrop) { addOption(Graphics.Anisotropic_Filter, anisotrop); }
	public String getAnisotropString() { return getValueOf(Graphics.Anisotropic_Filter); }
	public float getAnisotrop() { return new Float(getAnisotropString()).floatValue(); }
	
	public void setTextureQuality(String textureQuality) { addOption(Graphics.Texture_Quality, textureQuality); }
	public String getTextureQualityString() { return getValueOf(Graphics.Texture_Quality); }
	public String getTextureQuality() { return getOptionValueString(getTextureQualityString()); }
	
	public void setSpecularQuality(String specularQuality) { addOption(Graphics.Specular_Quality, specularQuality); }
	public String getSpecularQualityString() { return getValueOf(Graphics.Specular_Quality); }
	public String getSpecularQuality() { return getOptionValueString(getSpecularQualityString()); }
	
	public void setBumpQuality(String bumpQual) { addOption(Graphics.Bump_Mapping_Quality, bumpQual); }
	public String getBumpQualityString() { return getValueOf(Graphics.Bump_Mapping_Quality); }
	public String getBumpQuality() { return getOptionValueString(getBumpQualityString()); }
	
	public void setNormalQuality(String normalQuality) { addOption(Graphics.Normal_Quality, normalQuality); }
	public String getNormalQualityString() { return getValueOf(Graphics.Normal_Quality); }
	public String getNormalQuality() { return getOptionValueString(getNormalQualityString()); }
	
	public void setShaderQuality(String shaderQuality) { addOption(Graphics.Shader_Quality, shaderQuality); }
	public String getShaderQualityString() { return getValueOf(Graphics.Shader_Quality); }
	public String getShaderQuality() { return getOptionValueString(getShaderQualityString()); }

	public void setEffectsQuality(String EffectsQuality) { addOption(Graphics.Effects_Quality, EffectsQuality); }
	public String getEffectsQualityString() { return getValueOf(Graphics.Effects_Quality); }
	public String getEffectsQuality() { return getOptionValueString(getEffectsQualityString()); }
	
	public void setGeometryQuality(String geometry) { addOption(Graphics.Geometry_Quality, geometry); }
	public String getGeometryQualityString() { return getValueOf(Graphics.Geometry_Quality); }
	public String getGeometryQuality() { return getOptionValueString(getGeometryQualityString()); }
	
	public void setLOD(String lod) { addOption(Graphics.LOD, lod); }
	public String getLODString() { return getValueOf(Graphics.LOD); }
	public float getLOD() { return Float.valueOf(getLODString()).floatValue(); }
	
	public void setAntialiasing(String antialiasing) { addOption(Graphics.Antialiasing, antialiasing); }
	public String getAntialiasingString() { return getValueOf(Graphics.Antialiasing); }
	public int getAntialiasing() {
		String a = getAntialiasingString();
		if(a.equals(OptionValues.Off.toString())) return 0;
		int length = a.length();
		String antialiasing = a.substring(0, length - 1);
		return Integer.valueOf(antialiasing).intValue();
	}
	
	public String getOptionValueString(String value) {
		return value.toLowerCase();
	}
}